<template>
	<view class="container">
		<image class="header" src="@/static/images/login-bg.png" mode="scaleToFill" />
		<view class="centerLayout">
			<view class="title">得意罗盘</view>
			<!-- #ifdef MP-WEIXIN -->
			<!-- <button class="btnLogin" open-type="getPhoneNumber"
				@getphonenumber="getPhoneNumber">
				一键登录
			</button> -->
			<button class="btnLogin" open-type="getPhoneNumber" @click="uniLogin">
				一键登录
			</button>
			<!-- #endif -->
		</view>
	</view>
</template>
<script>
import { apiLogin, apiQryUserInfo } from "@/api/login";
// import { StorageName } from "@/utils/system";
export default {
	components: {},
	data() {
		return {

		}
	},
	computed: {
	},
	methods: {
		// #region 登录
		// 微信获取手机号信息
		getPhoneNumber(datas) {
			console.log(datas)// 微信小程序返回的相关数据
			if (!datas.detail.iv) {
				// 没有授权
				uni.showModal({
					title: '提示',
					content: '您已拒绝授权，请重新点击并授权',
					showCancel: false,
					confirmColor: '#22BAC2',
					success(res) { }
				})
				return
			}
			this.uniLogin(datas)
		},
		uniLogin(datas) {
			// uni.showLoading({
			// 	title: '加载中',
			// 	mask: true
			// })
			uni.$u.route({
                url: '/pages/entry/index',
                type: 'tab'
            })
			// uni.login({
			// 	provider: 'weixin',
			// 	success: res => {
			// 		console.log(res)
			// 		const {code} = res
			// 		// const params = {
			// 		// 	jsCode: code,
			// 		// 	iv: datas.detail.iv,
			// 		// 	encryptedData: datas.detail.encryptedData
			// 		// }
			// 		// 请求后台登录
			// 		apiLogin({
			// 			code
			// 		}).then(res => {
			// 			// this.qryUserInfo()
			// 			console.log(res);
			// 			uni.$u.route({
			// 				url: '/pages/entry/index',
			// 				type: 'tab'
			// 			})
			// 		}).catch((err) => {
			// 			uni.showToast({
			// 				title: err.retDesc,
			// 				icon: "error"
			// 			})
			// 		})
			// 	}
			// });
		},
		qryUserInfo() {
			apiQryUserInfo().then(res => {
				console.log(res);
				uni.hideLoading()
				// TODO
				// uni.setStorageSync(StorageName.USERINFO, res.result)
                uni.$u.route({
                    url: '/pages/entry/index',
                    type: 'tab'
                })
			}).catch((err) => {
				uni.showToast({
					title: err.retDesc,
					icon: "error"
				})
			})
		},
	}
}
</script>

<style lang="scss" scoped>
.container {
	width: 100%;
	height: 100%;
	min-height: 100vh;
	display: flex;
	flex-direction: column;

	.header {
		width: 100%;
		height: 521rpx;
	}
}

.centerLayout {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: flex-start;
	margin-top: -200rpx;

	.logoImg {
		width: 200rpx;
		height: 200rpx;
	}

	.title {
		font-size: 48rpx;
		font-weight: 700;
		color: #333333;
		line-height: 56rpx;
		margin-top: 40rpx;
	}

	.btnLogin {
		color: #FFFCF7;
		font-size: 36rpx;
		text-align: center;
		letter-spacing: 1rpx;
		margin-top: 66rpx;
		width: 636rpx;
		height: 108rpx;
		line-height: 108rpx;
		background: linear-gradient(101deg, #4fc68d 0%, #18b6cc 100%);
		border-radius: 54rpx;
	}
}

.agreementLayout {
	position: absolute;
	bottom: 5%;
	left: 50%;
	transform: translateX(-50%);
	width: 90%;
	color: #828282;
	font-size: 24rpx;
	display: flex;
	letter-spacing: 1rpx;

}

.agreementTxt {
	color: #22BAC2;
	font-weight: 500;
}
</style>
